<?php

namespace app\admin\dao;

use app\common\model\PromotionGroupRoiConsume;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * PromotionGroupRoiConsumeDao 数据访问对象
 * Class PromotionGroupRoiConsumeDao
 * @package app\admin\dao
 * @method PromotionGroupRoiConsume findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method PromotionGroupRoiConsume insertActive(array $params, array $allow_field = [])
 * @method PromotionGroupRoiConsume updateActive(PromotionGroupRoiConsume $model, array $params, array $allow_field = [])
 * @method PromotionGroupRoiConsume findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method PromotionGroupRoiConsume updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(PromotionGroupRoiConsume $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class PromotionGroupRoiConsumeDao
{
    use DaoTrait;

    /**
     * @var PromotionGroupRoiConsume
     */
    private $baseModel;

    /**
     * PromotionGroupRoiConsumeDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = PromotionGroupRoiConsume::class;
    }

    public function deleteByUK($promotionGroupId, $date): void
    {

        PromotionGroupRoiConsume::destroy(fn($query) => $query->where('promotionGroupId', $promotionGroupId)->where('date', $date), true);
    }

    public function select($promotionGroupId, $startTime, $endTime)
    {
        return PromotionGroupRoiConsume::where('promotionGroupId', $promotionGroupId)
            ->where('date', '>=', date('Y-m-d', $startTime))
            ->where('date', '<=', date('Y-m-d', $endTime))
            ->order('date', 'ASC')
            ->select();
    }
}
